﻿// Copyright (c) Microsoft Corporation, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.Web.UnitTest {
    using System;
    using System.Configuration;
    using System.Web.Configuration;

    // Allows a test to temporarily change Machine Key configuration settings 
    public class MachineKeySectionContext : ConfigurationSectionContext {

        private MachineKeySectionContext(MachineKeySection section)
            : base("system.web/machineKey", section)
        {
        }

        public static MachineKeySectionContext FromAutoGeneratedDecryptionKey() {

            return FromExplicitDecryptionKey("AutoGenerate");
        }

        public static MachineKeySectionContext FromDefaultDecryptionKey() {

            return FromExplicitDecryptionKey("ABAA84D7EC4BB56D75D217CECFFB9628809BDB8BF91CFCD64568A145BE59719F");
        }

        public static MachineKeySectionContext FromExplicitDecryptionKey(string decryptionKey) {

            MachineKeySection section = new MachineKeySection();
            section.Decryption = "AES";
            section.DecryptionKey = decryptionKey;

            return new MachineKeySectionContext(section);
        }
    }
}
